<template>
	<view>
		<view v-for="(item) in list" @click="clickPost(item.id)">
			<hm-cover-card :options="item"></hm-cover-card>
		</view>
		<view class="release-fixed" @click.stop="clickReleasePost">
			+
		</view>
	</view>
</template>

<script>
	import HmCoverCard from '@/components/hm-cover-card/index.vue'
	import {
		listPost
	} from '@/api/post.js'

	import config from '@/config'

	export default {

		components: {
			HmCoverCard
		},
		data() {
			return {
				options: {
					entryPic: '/static/images/img_25361_0_1.png',
					title: '单色摄影',
					text: '456张风景照片',
					shoucang: '/static/images/img_25361_0_0.png'
				},
				list: []
			};
		},
		onLoad() {
			uni.startPullDownRefresh();
			this.listPost()
		},
		methods: {
			onPullDownRefresh() {
				this.listPost()
				setTimeout(function() {
					uni.stopPullDownRefresh();
				}, 1000);
			},
			listPost() {
				listPost().then(res => {
					console.log(res)
					this.list = []
					for (var i = 0; i < res.data.length; i++) {
						const option = {
							id: res.data[i].id,
							entryPic: config.baseUrl + res.data[i].imgList,
							title: res.data[i].title,
						}
						this.list.push(option)
					}
					console.log(this.list)
				})
			},
			clickReleasePost() {
				uni.navigateTo({
					url: '/pages/post-release/post-release'
				})
			},
			clickPost(item) {
				uni.navigateTo({
					url: '/pages/post-detail/post-detail?id=' + item
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.release-fixed {
		position: fixed;
		/* #ifdef MP */
		bottom: 50rpx;
		/* #endif */
		/* #ifndef MP */
		bottom: calc(130rpx + constant(safe-area-inset-bottom));
		bottom: calc(130rpx + env(safe-area-inset-bottom));
		/* #endif */
		right: 20rpx;
		background-color: #55aaff;
		color: #fff;
		height: 80rpx;
		width: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 50%;
	}
</style>